package JZ;
/**
 * 正则表达式，动态规划问题
 */

import java.util.*;

public class jz19_正则表达式 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s = sc.nextLine().split(",");
        String s1 = s[0].substring(1, s[0].length() - 1);
        String s2 = s[1].substring(1, s[1].length() - 1);
        int m = s1.length();
        int n = s2.length();
        boolean[][] dp = new boolean[m + 1][n + 1];
        dp[0][0] = true;
        for (int i = 1; i <= n; i++) {
            if(s2.charAt(i - 1) == '*')
                dp[0][i] = dp[0][i - 2];
        }
        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= n; j++) {
                if(s1.charAt(i - 1) == s2.charAt(j - 1) || s2.charAt(j - 1) == '.'){
                    dp[i][j] = dp[i - 1][j - 1];
                }
                else if(s2.charAt(j - 1) == '*'){
                    if(s1.charAt(i - 1) != s2.charAt(j - 2) && s2.charAt(j - 2) != '.'){
                        dp[i][j] = dp[i][j - 2];
                    }
                    else
                        dp[i][j] = dp[i][j - 2] || dp[i - 1][j];
                }
            }
        }
        System.out.println(dp[m][n]);
    }
}
